package com.atguigu.spzx.manager.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.product.Brand;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.product.Category;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.product.CategoryBrand;
import com.atguigu.spyx.model.vo.system.CategoryBrandVo;
import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2023-11-09-10:10
 */
@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {

    @Resource
    CategoryBrandService categoryBrandService;

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        categoryBrandService.deleteById(id);
        return Result.ok();
    }

    @PostMapping("/save")
    public Result save(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id){
        CategoryBrand categoryBrand = categoryBrandService.getById(id);
        return Result.ok().data(categoryBrand);
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateById(categoryBrand);
        return Result.ok();
    }

    @GetMapping("/page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize,
                       CategoryBrand categoryBrand){
        PageInfo<CategoryBrandVo> pageInfo = categoryBrandService.page(pageNum,pageSize,categoryBrand);
        return Result.ok().data(pageInfo);
    }

    @GetMapping("/findBrandByCategoryId/{C3id}")
    public Result findBrandByCategoryId(@PathVariable Long C3id){
        List<Brand> list = categoryBrandService.findBrandByCategoryId(C3id);
        return Result.ok().data(list);
    }





}
